/* 
 * File:   Main.cpp
 * Author: Guilherme Monteiro
 *
 */

#include <cstdlib>
#include "../TableTranscriber2/headers/Cell.h"
#include "../TableTranscriber2/headers/GenericAdapter.h"
#include "../TableTranscriber2/headers/File.h"
#include "../TableTranscriber2/headers/FileWriter.h"
#include "headers/ZoomingSelector.h"

using namespace std;

/**
 * Main function of ZoomingSelector.
 * 
 * @param argc
 * @param argv
 * @return 0 if it ends without errors
 */
int main(int argc, char** argv) { 
    if(argc == 2) {
        try {
            printf("argv[0]: %s\n", argv[0]);
            printf("argv[1]: %s\n", argv[1]);
            
            string highTablePath = argv[1];
            MetaInfoZooming* meta = new MetaInfoZooming(highTablePath);

            ZoomingSelector* selector = new ZoomingSelector(meta->getHighResolutionTablePath());
            vector<Cell> selections = selector->run();
            
            GenericAdapter* genericAdapter = new GenericAdapter(HIGH_2_LOW, meta);
            vector<Cell> selectionsAdapted = genericAdapter->adaptCells(selections);         
            
            FileWriter* fileWriter = new FileWriter(meta->getOutputSelectionsFileName());
            fileWriter->writeHeader1(cvPoint(0,0), cvPoint(DEFAULT_WIDTH, DEFAULT_HEIGHT));
            fileWriter->writeCells(selectionsAdapted);
              
            cout << "====> ZoomingSelector executed with success." << endl;  
        }
        catch(NullImageException &nie) {
            cerr << nie.what() << endl;
        }
        catch(InvalidFileException &ife) {
            cerr << ife.what() << endl;
        }
        catch(exception &e) {
            cerr << "Some error ocurred. Please, report the bug to guilherme.gadelha [at] ccc [dot] ufcg [dot] edu [dot] br" << endl;
        }
    }
    else {
        cerr << "Invalid number of arguments. Verify README to know more." << endl;
    }
    
    return 0;
}

